package com.darren.framework.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
  
  
public class CrossDomainFilter implements Filter {  
      
    public CrossDomainFilter() {  
        super();  
    }  
  
    @Override  
    public void init(FilterConfig filterConfig){}  
      

  
    @Override  
    public void doFilter(ServletRequest request, ServletResponse response,  
            FilterChain chain) throws IOException, ServletException {
    	
    	 HttpServletResponse myResponse = (HttpServletResponse) response;    	 
    	 myResponse.setHeader("Access-Control-Allow-Origin", "*");       
    	 myResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE");
    	 myResponse.setHeader("Access-Control-Max-Age", "3600");
    	 myResponse.setHeader("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,Language,Authorization,accessToken,refreshToken"); 		
    	 myResponse.setHeader("Access-Control-Expose-Headers", "Authorization,DateFormat,accessToken,refreshToken");
         chain.doFilter(request, response);
    }  
  
    @Override  
    public void destroy() {} 
    
}